﻿@model Inscriptionem.Areas.Inscriptionem.Models.Views.PostViewModel

@{
    ViewBag.Title = "Inscriptionem » Posts » Edit Post";
    Layout = "../Shared/Layout.cshtml";

    ViewBag.CurrentPage = "Posts";

    string message = string.Empty;

    switch (Model.Error)
    {
        case Inscriptionem.Areas.Inscriptionem.Models.Enums.PostError.PostCategoriesEmpty:
        case Inscriptionem.Areas.Inscriptionem.Models.Enums.PostError.PostCategoriesIncorrect:
            {
                message = "Please enter Post Categories.";
                break;
            }

        case Inscriptionem.Areas.Inscriptionem.Models.Enums.PostError.PostCategoriesFromDifferentSections:
            {
                message = "Please enter Post Categories from single Section.";
                break;
            }
            
        case Inscriptionem.Areas.Inscriptionem.Models.Enums.PostError.Other:
        {
            message = "Unknown error occurred, please try again.";
            break;
        }
    }
}

<link rel="stylesheet" href="/Content/Themes/jQueryUI/jquery-ui.min.css" />

<script src="/Content/Scripts/jQuery/jquery.min.js"></script>
<script src="/Content/Scripts/jQueryUI/jquery-ui.min.js"></script>
<script src="/Content/Scripts/jQueryUI/jquery.ui.datepicker.min.js"></script>

<div class="outer" id="contentwrap">
    @{Html.RenderPartial("NavigationMenu");}
    <div class="postcont">
		<div id="content">
            <div class="post type-post status-publish format-standard hentry">
                <h2 class="title">Edit Post</h2>
                <div class="postdate-single error-message">@message</div>
                <hr />
                <form method="post" action="/Inscriptionem/Post/Edit">
				    <div class="entry">
                        <input type="hidden" name="ID" value="@Model.ID" />
                        <p>Title <input type="text" name="Title" style="margin-right: 0px; width: 700px;" value="@Model.Title" /></p>
                        <p>
                            <textarea name="Content" style="width: 610px;">@Model.Content</textarea>
                            <select name="Categories" style="float: right; height: 262px; width: 150px; margin-right: 0px;" multiple>
                            @foreach (var language in Model.Languages)
                            {
                                if (language.Sections.Any())
                                {
                                <text>
                                <optgroup label="@language.Name / @language.LocalizedName">
                                    @foreach (var section in language.Sections.OrderBy(s => s.Order))
                                    {
                                        if (section.Categories.Any())
                                        {
                                        <text>
                                        <optgroup label="  @(section.Name) /@(section.LocalizedName)">
                                            @foreach (var category in section.Categories.OrderBy(c => c.Order))
                                            {
                                            <text>
                                            <option value="@category.ID" @(Model.Categories.Contains(category.ID) ? "selected" : string.Empty)>@category.Name</option>
                                            </text>
                                            }
                                        </optgroup>
                                        </text>
                                        }
                                    }
                                </optgroup>
                                </text>
                                }
                            }
                            </select>
                        </p>
                        <p>Tags <input type="text" name="Tags" style="margin-right: 0px; width: 700px;" value="@Model.Tags" /></p>                        
                        <p style="margin-top: 20px;">Is Published <input type="checkbox" name="IsPublished" @(Model.IsPublished ? "checked" : string.Empty) /></p>
                        <p>Is Section Pinned <input type="checkbox" name="IsSectionPinned" @(Model.IsSectionPinned ? "checked" : string.Empty) /></p>
                        <p>Is Category Pinned <input type="checkbox" name="IsCategoryPinned" @(Model.IsCategoryPinned ? "checked" : string.Empty) /></p>
                        <p>Is Commentable <input type="checkbox" name="IsCommentable" @(Model.IsCommentable ? "checked" : string.Empty) /></p>
                        <p>Date <input type="text" id="CreatedDate" name="CreatedDate" value="@(Model.CreatedDate.HasValue ? Model.CreatedDate.Value.ToShortDateString() : string.Empty)" /></p>
                        <p>Create post set <input type="checkbox" name="CreateSet" />
                        <br />
                        or select existing set 
                        <select name="SetID">
                            <option value="0">(None)</option>
                            @foreach (var set in Model.Sets)
                            { 
                            <text>
                            <option value="@set.ID" @(set.ID == Model.SetID ? "selected" : string.Empty)>@string.Join(", ", set.Posts.Select(p => p.Title).ToArray())</option>
                            </text>
                            }
                        </select>
                        </p>
                        <p>
                        <p style="padding-top: 5px;">Created By <input type="text" name="MemberName" value="@(Model.Member == null ? string.Empty : Model.Member.FirstName + " " + Model.Member.LastName)" disabled="disabled" /></p>
                        <input type="hidden" name="MemberID" value="@(Model.Member == null ? Inscriptionem.Authorization.Member.Current.ID : Model.Member.ID)" />
                     </div>

                    <input type="reset" value="Reset" />&nbsp;|&nbsp;<input type="submit" value="Edit" />
                </form>
			</div>
        </div>
	</div>	
</div>

<script type="text/javascript">
    $(function () {
        $("#CreatedDate").datepicker();
    });
</script>